/*
 * ******************************************************************************
 *   Copyright (c) 2013-2014 Gabriele Mariotti.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *  *****************************************************************************
 */

package it.gmariotti.cardslib.demo.fragment;

import it.gmariotti.cardslib.demo.CollectionViewCallbacks;
import it.gmariotti.cardslib.demo.ResourceTable;
import it.gmariotti.cardslib.demo.fragment.v1.*;
import it.gmariotti.cardslib.demo.ui.widget.CollectionView;
import it.gmariotti.cardslib.library.Constants;
import ohos.app.Context;
import ohos.global.resource.NotExistException;
import ohos.global.resource.WrongTypeException;
import ohos.hiviewdfx.HiLog;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


/**
 * @author Gabriele Mariotti (gabri.mariotti@gmail.com)
 */
public class V1DashFragment extends NativeDashFragment {

    public static V1DashFragment newInstance() {
        return new V1DashFragment();
    }

    protected NativeDashAdapter buildAdapter() {
        return new V1DashAdapter(getAbility(), buildMenuList());
    }

    private static class V1DashAdapter extends NativeDashFragment.NativeDashAdapter implements CollectionViewCallbacks {

        int TOKEN = 0x1;
        int TOKEN2 = 0x2;
        int TOKEN3 = 0x3;
        int TOKEN4 = 0x4;
        int TOKEN5 = 0x5;

        public V1DashAdapter(Context context, List<MenuEntry> objects) {
            super(context, objects);
        }

        public CollectionView.Inventory getInventory() {
            CollectionView.Inventory inventory = new CollectionView.Inventory();

            try {
                inventory.addGroup(new CollectionView.InventoryGroup(TOKEN)
                        .setDisplayCols(mContext.getResourceManager().getElement(ResourceTable.Integer_menu_grid_columns).getInteger())
                        .setItemCount(5)
                        .setHeaderLabel(mContext.getString(ResourceTable.String_header_title_group1))
                        .setShowHeader(true));

                inventory.addGroup(new CollectionView.InventoryGroup(TOKEN2)
                        .setDisplayCols(mContext.getResourceManager().getElement(ResourceTable.Integer_menu_grid_columns).getInteger())
                        .setItemCount(4)
                        .setDataIndexStart(5)
                        .setHeaderLabel(mContext.getString(ResourceTable.String_header_title_group2))
                        .setShowHeader(true));

                inventory.addGroup(new CollectionView.InventoryGroup(TOKEN3)
                        .setDisplayCols(mContext.getResourceManager().getElement(ResourceTable.Integer_menu_grid_columns).getInteger())
                        .setItemCount(11)
                        .setDataIndexStart(9)
                        .setHeaderLabel(mContext.getString(ResourceTable.String_header_title_group3))
                        .setShowHeader(true));

       /*     inventory.addGroup(new CollectionView.InventoryGroup(TOKEN4)
                    .setDisplayCols(mContext.getResourceManager().getInteger(ResourceTable.Integer_menu_grid_columns).getInteger()))
                    .setItemCount(3)
                    .setDataIndexStart(20)
                    .setHeaderLabel(mContext.getString(ResourceTable.String_header_title_group4))
                    .setShowHeader(true));
       */
                inventory.addGroup(new CollectionView.InventoryGroup(TOKEN5)
                        .setDisplayCols(mContext.getResourceManager().getElement(ResourceTable.Integer_menu_grid_columns).getInteger())
                        .setItemCount(3)
                        .setDataIndexStart(20)
                        .setHeaderLabel(mContext.getString(ResourceTable.String_header_title_group5))
                        .setShowHeader(true));
            } catch (Exception e) {
                 HiLog.error(Constants.LABEL_LOG,e.toString());
            }

            return inventory;
        }

    }


    private static List<MenuEntry> buildMenuList() {
        ArrayList<MenuEntry> list = new ArrayList<MenuEntry>();
        list.add(new MenuEntry(ResourceTable.String_carddemo_title_tag_base_header, ResourceTable.Color_md_indigo_200, ResourceTable.String_header_title_cardheadersubtitle, HeaderFragment.class));
        list.add(new MenuEntry(ResourceTable.String_carddemo_title_tag_base_shadow, ResourceTable.Color_md_green_300, ResourceTable.String_header_title_cardshadowsubtitle, ShadowFragment.class));
        list.add(new MenuEntry(ResourceTable.String_carddemo_title_tag_base_thumbnail, ResourceTable.Color_md_orange_300, ResourceTable.String_header_title_cardthumbnailsubtitle, ThumbnailFragment.class));
        list.add(new MenuEntry(ResourceTable.String_carddemo_title_tag_base_card, ResourceTable.Color_md_yellow_700, ResourceTable.String_header_title_cardsubtitle, CardFragment.class));
        list.add(new MenuEntry(ResourceTable.String_carddemo_title_tag_base_card_expand, ResourceTable.Color_md_cyan_400, ResourceTable.String_header_title_cardexpandsubtitle, CardExpandFragment.class));

        list.add(new MenuEntry(ResourceTable.String_carddemo_title_tag_ex_birthday_card, ResourceTable.Color_md_green_300, ResourceTable.String_header_title_subtitle_ex_gbirth, BirthDayCardFragment.class));
        list.add(new MenuEntry(ResourceTable.String_carddemo_title_tag_ex_gplay, ResourceTable.Color_md_teal_200, ResourceTable.String_header_title_subtitle_ex_gplay, GPlayCardFragment.class));
        //list.add(new MenuEntry(ResourceTable.String_carddemo_title_tag_ex_stock_card,ResourceTable.Color_md_indigo_600,ResourceTable.String_header_title_subtitle_ex_gstock, StockCardFragment.class));
        list.add(new MenuEntry(ResourceTable.String_carddemo_title_tag_ex_misc_card, ResourceTable.Color_md_indigo_A400, ResourceTable.String_header_title_subtitle_ex_misc, MiscCardFragment.class));
        list.add(new MenuEntry(ResourceTable.String_carddemo_title_tag_ex_card_changevalue, ResourceTable.Color_md_pink_A200, ResourceTable.String_header_title_subtitle_ex_refresh, ChangeValueCardFragment.class));

        list.add(new MenuEntry(ResourceTable.String_carddemo_title_tag_list_base, ResourceTable.Color_md_brown_300, ResourceTable.String_header_title_subtitle_lbase, ListBaseFragment.class));
        list.add(new MenuEntry(ResourceTable.String_carddemo_title_tag_list_base_different_layout, ResourceTable.Color_md_green_600, ResourceTable.String_header_title_subtitle_ldiff, ListDifferentInnerBaseFragment.class));
        list.add(new MenuEntry(ResourceTable.String_carddemo_title_tag_list_expandable_card, ResourceTable.Color_md_blue_600, ResourceTable.String_header_title_subtitle_lexpand, ListExpandCardFragment.class));
        list.add(new MenuEntry(ResourceTable.String_carddemo_title_tag_list_google_play, ResourceTable.Color_md_blue_A200, ResourceTable.String_header_title_subtitle_lgplay, ListGplayCardFragment.class));
        list.add(new MenuEntry(ResourceTable.String_carddemo_title_tag_list_swipe_undo, ResourceTable.Color_md_blue_A200, ResourceTable.String_header_title_subtitle_swipe, ListGplayUndoCardFragment.class));
        list.add(new MenuEntry(ResourceTable.String_carddemo_title_tag_list_grid_base, ResourceTable.Color_md_cyan_700, ResourceTable.String_header_title_subtitle_gbase, GridBaseFragment.class));
        list.add(new MenuEntry(ResourceTable.String_carddemo_title_tag_list_grid_google_play, ResourceTable.Color_md_red_800, ResourceTable.String_header_title_subtitle_ggplay, GridGplayFragment.class));
        list.add(new MenuEntry(ResourceTable.String_carddemo_title_tag_list_colored, ResourceTable.Color_md_blue_900, ResourceTable.String_header_title_subtitle_lcolored, ListColorFragment.class));
//        list.add(new MenuEntry(ResourceTable.String_carddemo_title_tag_list_cursor,ResourceTable.Color_md_orange_800,ResourceTable.String_header_title_subtitle_lcursor, ListCursorCardFragment.class));
//        list.add(new MenuEntry(ResourceTable.String_carddemo_title_tag_list_grid_cursor,ResourceTable.Color_md_brown_400,ResourceTable.String_header_title_subtitle_gcursor, GridCursorCardFragment.class));
//        list.add(new MenuEntry(ResourceTable.String_carddemo_title_tag_list_recyclerView,ResourceTable.Color_md_orange_200,ResourceTable.String_header_title_subtitle_recyclerview, RecyclerViewFragment.class));

        //list.add(new MenuEntry(ResourceTable.String_carddemo_title_tag_cab_multichoice,ResourceTable.Color_md_green_500,ResourceTable.String_header_title_subtitle_cab_multi, ListGplayCardCABFragment.class));
        //list.add(new MenuEntry(ResourceTable.String_carddemo_title_tag_cab_grid_multichoice,ResourceTable.Color_md_deep_orange_900,ResourceTable.String_header_title_subtitle_cab_gmulti, GridGplayCABFragment.class));
        //list.add(new MenuEntry(ResourceTable.String_carddemo_title_tag_cab_cursor_multichoice,ResourceTable.Color_md_purple_400,ResourceTable.String_header_title_subtitle_cab_lcursor, ListGplayCursorCardCABFragment.class));

        list.add(new MenuEntry(ResourceTable.String_carddemo_title_tag_misc_cardwithlist, ResourceTable.Color_md_deep_purple_500, ResourceTable.String_header_title_subtitle_cardwithlist, CardWithListFragment.class));
        list.add(new MenuEntry(ResourceTable.String_carddemo_title_tag_misc_sectioned, ResourceTable.Color_md_indigo_300, ResourceTable.String_header_title_subtitle_sectioned, ListSectionedCardFragment.class));
        list.add(new MenuEntry(ResourceTable.String_carddemo_title_tag_misc_dismiss, ResourceTable.Color_md_teal_300, ResourceTable.String_header_title_subtitle_dismiss, DismissAnimFragment.class));

        return list;
    }
}
